﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Text;

namespace DataManager.DAL
{
    public struct Customer
    {
        int m_CustomerId;
        string m_CustomerName;
        string m_Address;
        string m_Email;

        public int CustomerId
        {
            get { return m_CustomerId; }
            set { m_CustomerId = value; }
        }

        public string CustomerName
        {
            get { return m_CustomerName; }
            set { m_CustomerName = value; }
        }

        public string Address
        {
            get { return m_Address; }
            set { m_Address = value; }
        }

        public string Email
        {
            get { return m_Email; }
            set { m_Email = value; }
        }
    }

    class Customers:DAL
    {
        /// <summary>
        /// Visszateriti a kereses szerint a vasarlok listajat, ha nincs parameter akkor az osszeset.
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public List<Customer> GetCustomerList(string name)
        {
            string query = "SELECT VasarloId, Nev, Cim, EmailCim " +
                "FROM Vasarlok ";
            if (name != "")
            {
                query = query + "WHERE Nev LIKE '%" + name + "%'";
            }
            string error = string.Empty;
            SqlDataReader rdr = ExecuteReader(query, ref error);
            List<Customer> customerList = new List<Customer>();
            if (error == "OK")
            {
                while (rdr.Read())
                {
                    Customer item = new Customer();
                    item.CustomerId = Convert.ToInt32(rdr["VasarloId"]);
                    item.CustomerName = rdr["Nev"].ToString();
                    item.Address = rdr["Cim"].ToString();
                    item.Email = rdr["EmailCim"].ToString();
                    customerList.Add(item);
                }
            }
            CloseDataReader(rdr);
            return customerList;
        }
    }
}
